/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.cestum.cave.ui.components
{
import flash.events.Event;
import flash.events.MouseEvent;

import org.cestum.cave.ui.CaveView;
import org.cestum.cave.ui.events.BtnClickEvent;

import spark.components.Button;


//icons
[Style(name="iconUp",type="*")]
[Style(name="iconOver",type="*")]
[Style(name="iconDown",type="*")]
[Style(name="iconDisabled",type="*")]
//paddings
[Style(name="paddingLeft",type="Number")]
[Style(name="paddingRight",type="Number")]
[Style(name="paddingTop",type="Number")]
[Style(name="paddingBottom",type="Number")]

[Event(name="imageButtonClick",type="org.cestum.cave.ui.events.BtnClickEvent")]
[ManagedEvents("imageButtonClick", scope="local")]
public class ImageButton extends Button {
	
	public function ImageButton()	{
		super();
		//This is only useful if you trying to dispatch parsley events
		addEventListener(Event.ADDED_TO_STAGE, addToStage);
	}
	override protected function clickHandler(event:MouseEvent):void {
		var btn:Button = (event.currentTarget as Button);
		var myParent:Object = btn.document;
		if (myParent instanceof CaveView)
			myParent.handleBtnEvent(event);
		else
			//if parent lookup failed, dispatch an Event to CaveView
			dispatchEvent(new BtnClickEvent(BtnClickEvent.BTNCLICK, btn.id));

	}
	public function addToStage(event:Event):void {
		dispatchEvent(new Event('configureIOC', true));
	}
}

}